#include "ArrayInputDevice.h"

std::size_t Common::ArrayInputDevice::readBlock(char * buf, boost::int64_t from, boost::int64_t to) throw (InputDeviceException)
{
	std::size_t size = to - from;

	if ( from > to )
	{
		throw InputDeviceException("read array block failed : incorrect index");
	}

	if ( from > m_arr.size() )	
	{
		throw InputDeviceException("read array block failed : index out of bounds");
	}

	boost::int64_t border = to;

	if ( to > m_arr.size() )
	{
		border = m_arr.size();
	}

	for ( boost::int64_t i = from; i < border; ++i )
	{
		buf[i - from] = m_arr[i];
	}

	return size;
};
